# This contains only iOS/tvOS-simulator-specific jobs
# These are run as part of runtime-extra-platforms by default.
# But can also be triggered manually via `runtime-ioslikesimulator` name
#   /azp run runtime-ioslikesimulator

parameters:
  isExtraPlatformsBuild: false
  isiOSLikeSimulatorOnlyBuild: false
  isRollingBuild: false

jobs:

#
# iOS/tvOS interp - requires AOT Compilation and Interp flags
# Build the whole product using Mono and run libraries tests
#
- template: /eng/pipelines/common/platform-matrix.yml
  parameters:
    jobTemplate: /eng/pipelines/common/global-build-job.yml
    helixQueuesTemplate: /eng/pipelines/libraries/helix-queues-setup.yml
    buildConfig: Release
    runtimeFlavor: mono
    isExtraPlatformsBuild: ${{ parameters.isExtraPlatformsBuild }}
    isiOSLikeSimulatorOnlyBuild: ${{ parameters.isiOSLikeSimulatorOnlyBuild }}
    platforms:
    - iossimulator_x64
    - tvossimulator_x64
    # don't run tests on arm64 PRs until we can get significantly more devices
    - ${{ if eq(variables['isRollingBuild'], true) }}:
      - iossimulator_arm64
    variables:
      # map dependencies variables to local variables
      - name: librariesContainsChange
        value: $[ stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_libraries.containsChange'] ]
      - name: monoContainsChange
        value: $[ stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_mono_excluding_wasm.containsChange'] ]
    jobParameters:
      testGroup: innerloop
      nameSuffix: AllSubsets_Mono
      buildArgs: -s mono+libs+host+packs+libs.tests -c $(_BuildConfig) /p:ArchiveTests=true $(_runSmokeTestsOnlyArg) /p:RunAOTCompilation=true /p:MonoForceInterpreter=true /p:BuildDarwinFrameworks=true
      timeoutInMinutes: 180
      # extra steps, run tests
      postBuildSteps:
        - template: /eng/pipelines/libraries/helix.yml
          parameters:
            creator: dotnet-bot
            interpreter: true
            testRunNamePrefixSuffix: Mono_$(_BuildConfig)

#
# Build the whole product using Mono for iOSSimulator/tvOSSimulator and run runtime tests with iOS/tvOS simulators
#
- template: /eng/pipelines/common/platform-matrix.yml
  parameters:
    jobTemplate: /eng/pipelines/common/global-build-job.yml
    helixQueuesTemplate: /eng/pipelines/coreclr/templates/helix-queues-setup.yml
    buildConfig: Release
    runtimeFlavor: mono
    isExtraPlatformsBuild: ${{ parameters.isExtraPlatformsBuild }}
    isiOSLikeOnlyBuild: ${{ parameters.isiOSLikeOnlyBuild }}
    platforms:
      - iossimulator_x64
      - tvossimulator_x64
      # don't run tests on arm64 PRs until we can get significantly more devices
      - ${{ if eq(variables['isRollingBuild'], true) }}:
        - iossimulator_arm64
    variables:
      - ${{ if and(eq(variables['System.TeamProject'], 'public'), eq(variables['Build.Reason'], 'PullRequest')) }}:
        - name: _HelixSource
          value: pr/dotnet/runtime/$(Build.SourceBranch)
      - ${{ if and(eq(variables['System.TeamProject'], 'public'), ne(variables['Build.Reason'], 'PullRequest')) }}:
        - name: _HelixSource
          value: ci/dotnet/runtime/$(Build.SourceBranch)
      - name: timeoutPerTestInMinutes
        value: 60
      - name: timeoutPerTestCollectionInMinutes
        value: 180
    jobParameters:
      testGroup: innerloop
      nameSuffix: AllSubsets_Mono_RuntimeTests
      buildArgs: -s mono+libs -c $(_BuildConfig)
      timeoutInMinutes: 240
      # extra steps, run tests
      extraVariablesTemplates:
        - template: /eng/pipelines/common/templates/runtimes/test-variables.yml
          parameters:
            testGroup: innerloop
      postBuildSteps:
        - template: /eng/pipelines/common/templates/runtimes/build-runtime-tests-and-send-to-helix.yml
          parameters:
            creator: dotnet-bot
            compileOnHelix: true
            interpreter: true
            testBuildArgs: /p:ArchiveTests=true /p:DevTeamProvisioning=- /p:RunAOTCompilation=true /p:MonoForceInterpreter=true /p:BuildTestsOnHelix=true
            testRunNamePrefixSuffix: Mono_$(_BuildConfig)
            extraHelixArguments: /p:NeedsToBuildAppsOnHelix=true

#
# Build the whole product using Native AOT for iOSSimulator/tvOSSimulator and run runtime tests with iOS/tvOS simulators
#
- template: /eng/pipelines/common/platform-matrix.yml
  parameters:
    jobTemplate: /eng/pipelines/common/global-build-job.yml
    helixQueuesTemplate: /eng/pipelines/coreclr/templates/helix-queues-setup.yml
    buildConfig: Release
    runtimeFlavor: coreclr
    isExtraPlatformsBuild: ${{ parameters.isExtraPlatformsBuild }}
    isiOSLikeOnlyBuild: ${{ parameters.isiOSLikeOnlyBuild }}
    platforms:
      - iossimulator_x64
      - tvossimulator_x64
      # don't run tests on arm64 PRs until we can get significantly more devices
      - ${{ if eq(variables['isRollingBuild'], true) }}:
        - iossimulator_arm64
    variables:
      - ${{ if and(eq(variables['System.TeamProject'], 'public'), eq(variables['Build.Reason'], 'PullRequest')) }}:
        - name: _HelixSource
          value: pr/dotnet/runtime/$(Build.SourceBranch)
      - ${{ if and(eq(variables['System.TeamProject'], 'public'), ne(variables['Build.Reason'], 'PullRequest')) }}:
        - name: _HelixSource
          value: ci/dotnet/runtime/$(Build.SourceBranch)
      - name: timeoutPerTestInMinutes
        value: 60
      - name: timeoutPerTestCollectionInMinutes
        value: 180
    jobParameters:
      testGroup: innerloop
      nameSuffix: AllSubsets_NativeAOT_RuntimeTests
      timeoutInMinutes: 240
      buildArgs: --cross -s clr.alljits+clr.tools+clr.nativeaotruntime+clr.nativeaotlibs+libs -c $(_BuildConfig)
      # extra steps, run tests
      extraVariablesTemplates:
        - template: /eng/pipelines/common/templates/runtimes/test-variables.yml
          parameters:
            testGroup: innerloop
      postBuildSteps:
        - template: /eng/pipelines/common/templates/runtimes/build-runtime-tests-and-send-to-helix.yml
          parameters:
            creator: dotnet-bot
            testBuildArgs: tree nativeaot/SmokeTests /p:BuildNativeAOTRuntimePack=true
            testRunNamePrefixSuffix: NativeAOT_$(_BuildConfig)
